<?php
class ModelAccountSocial extends Model {
	public function addSocial($data) {
	     $this->db->query("INSERT INTO " . DB_PREFIX . "customer_social SET customer_id = '" . (int)$data['customer_id'] . "', social_uid = '" . $this->db->escape($data['uid']) . "', social_type = '" . (int)$data['social_type'] . "',status='1'");
	}

	public function getBindSocial($uid,$social_type) {

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_social WHERE social_uid = '" . $this->db->escape($uid) . "' and social_type = '" . $this->db->escape($social_type) . "' AND status='1'");

		return $query->row;
	}

	public function uidHasBinded($uid) {
		$query = $this->db->query("SELECT count(*) as total FROM " . DB_PREFIX . "customer_social WHERE social_uid = '" . $this->db->escape($uid) . "'");
		return $query->row['total'];
	}

	public function getSocials() {
	   $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_social WHERE customer_id = '" . (int)$this->customer->getId() . "'");
	   return $query->rows;
	}

    public function getSocialByCustomerId($customer_id,$social_type){
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_social WHERE customer_id = '" . (int)$customer_id . "' and social_type = '" . $this->db->escape($social_type) . "' AND status='1'");
        return $query->row;
    }

    public function updateSocial($data){
        $this->db->query("UPDATE " . DB_PREFIX . "customer_social SET  social_uid = '" . $this->db->escape($data['uid']) . "', social_type = '" . (int)$data['social_type'] . "',status= '1' where customer_id = '" . (int)$data['customer_id'] . "' and social_type = '".(int)$data['social_type']."'");
    }
	public function disableSocialByUid($uid) {
        $this->db->query("UPDATE " . DB_PREFIX . "customer_social SET status='0' WHERE customer_id = '" . (int)$this->customer->getId() . "' AND social_uid = '" . $this->db->escape($uid) . "'");
	}
}